local StoryBehavior = require("gameLogic.story.behavior.StoryBehavior")
local StoryCamera = class("StoryCamera", StoryBehavior)
local GameUtils = require("utils.GameUtils")

function StoryCamera:ctor()
    StoryCamera.super.ctor(self)
end

function StoryCamera:_active()
    if self._camera then
        return
    end
    self._camera = self:getActuator():getStoryCamera()
    local params = self:getParams()
    if params.duration <= 0 then
        self:_moveCameraImmediately()
    else
        self:_moveCameraWithAction()
    end
end

function StoryCamera:_moveCameraImmediately()
    local params = self:getParams()
    local pos = params.pos
    local eulerAngles = params.eulerAngles
    self._camera.transform.position = pos
    self._camera.transform.eulerAngles = eulerAngles
    self:setDone(true)
end

function StoryCamera:_moveCameraWithAction()
    local params = self:getParams()
    local moveTo = self._camera.transform:DOMove(params.pos, params.duration)
    self._camera.transform:DORotate(params.eulerAngles, params.duration)
    local sequence = DOTween.Sequence()
    sequence:Append(moveTo)
    sequence:AppendCallback(
        function()
            self:setDone(true)
        end
    )
end

return StoryCamera
